﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoShopping.Model;

namespace GoShopping.BLL
{
    /// <summary>
    /// 友情链接维护类
    /// </summary>
    public class FriendlyLinkBean
    {
        /// <summary>
        /// 获取所有友情链接列表
        /// </summary>
        /// <returns></returns>
        public IList<FriendlyLink> GetAllFriendlyLink()
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.FriendlyLink).ToList<FriendlyLink>();
        }

        /// <summary>
        /// 查询FriendlyLink
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FriendlyLink GetFriendlyLink(int id)
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.FriendlyLink).Where(
                GoShoppingNBear.FriendlyLink.ID == id
                ).ToSingleObject<FriendlyLink>();
        }

        /// <summary>
        /// 删除友情链接
        /// </summary>
        /// <param name="FriendlyLinkID"></param>
        /// <returns></returns>
        public bool DelFriendlyLink(string FriendlyLinkID)
        {
            int i = Databases.DBGoShopping.Delete(GoShoppingNBear.FriendlyLink).Where(
                GoShoppingNBear.FriendlyLink.ID == FriendlyLinkID).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 更新一个友情链接
        /// </summary>
        /// <param name="FriendlyLink"></param>
        /// <returns></returns>
        public bool UpdateFriendlyLink(FriendlyLink FriendlyLink)
        {
            int i = Databases.DBGoShopping.Update(GoShoppingNBear.FriendlyLink).AddColumn(
                GoShoppingNBear.FriendlyLink.LinkUrl, FriendlyLink.LinkUrl).AddColumn(
                GoShoppingNBear.FriendlyLink.Order, FriendlyLink.Order).AddColumn(
                GoShoppingNBear.FriendlyLink.Title, FriendlyLink.Title).Where(
                GoShoppingNBear.FriendlyLink.ID == FriendlyLink).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 添加一个友情链接
        /// </summary>
        /// <param name="FriendlyLink"></param>
        /// <returns></returns>
        public bool AddFriendlyLink(FriendlyLink FriendlyLink)
        {
            int i = Databases.DBGoShopping.Insert(GoShoppingNBear.FriendlyLink).AddColumn(
                GoShoppingNBear.FriendlyLink.LinkUrl, FriendlyLink.LinkUrl).AddColumn(
                GoShoppingNBear.FriendlyLink.Order, FriendlyLink.Order).AddColumn(
                GoShoppingNBear.FriendlyLink.Title, FriendlyLink.Title).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
